package com.ph.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.view.InternalResourceViewResolver;
import org.springframework.web.servlet.view.JstlView;

import com.ph.interceptor.LoginInterceptor;

/**
 * @项目：phshopping-api-platform
 *
 * @描述：后台web项目配置
 *
 * @作者： Mr.chang
 *
 * @创建时间：2017年3月14日
 *
 * @Copyright @2017 by Mr.chang
 */
@EnableWebMvc
@Configuration
public class WebConfig extends WebMvcConfigurerAdapter{

	/**
	 * 静态资源拦截器
	 */
	@Override
	public void addResourceHandlers(ResourceHandlerRegistry registry) {
		 registry.addResourceHandler("/static/**","/favicon.ico").addResourceLocations("classpath:/static/","/favicon.ico");
		 super.addResourceHandlers(registry);
	}
	
	/**
	 * 登录拦截器
	 */
	@Override
	public void addInterceptors(InterceptorRegistry registry) {
		registry.addInterceptor(new LoginInterceptor()).
		addPathPatterns("/**").
		excludePathPatterns("/login","/doLogin","/member/usersync/**","/api/pay/**","/api/hunter/getprovinces","/api/hunter/getcities",
				"/api/hunter/getcounties","/api/hunter/gettowns","/api/hunter/addhunterprofit","/api/hunter/findarea",
				"/api/hunter/findarea/findtownlist","/api/order/**");
	}
	
	/**	
	 * jsp解析器
	 * @return
	 */
	@Bean
    public InternalResourceViewResolver viewResolver() {
        InternalResourceViewResolver resolver = new InternalResourceViewResolver();
        resolver.setPrefix("/WEB-INF/jsp/");
        resolver.setSuffix(".jsp");
        resolver.setViewClass(JstlView.class);
        return resolver;
    }
	
	
	
	

}
